function addSystemAdminRoleWin(grid) {
	var win = addAdminRoleWin(grid);
	var panel = win.findById('addPanelForm');
	panel.findById('_company_chinese_name').hideLabel = true;
	panel.findById('_company_chinese_name').hide();
	return win;
}

function addClientAdminRoleWin(grid) {
	var win = addAdminRoleWin(grid);
	win.setTitle('新增客户系统管理员账户');
	var panel = win.findById('addPanelForm');
	panel.getForm().url = 'CusAdmin!addClientSystemAdmin.action';
	return win;
}

function addAdminRoleWin(grid) {
	var addSystemAdminRolePanel = new Ext.form.FormPanel({
		frame:true,
		id:'addPanelForm',
		bodyStyle:'padding:5px 5px 0',
		url:'CusAdmin!addSystemAdmin.action',
		items:[{
				layout:'column',
				items:[{
					columnWidth:1,
					layout:'form',
					items:[{
						xtype:'hidden',
						name:'_company_code',
						id:'_company_code'
					},{
						xtype:'textfield',
						fieldLabel: '公司名',
						name:'_company_chinese_name',
						id:'_company_chinese_name',
						disabled:true
					}]
				},{
					columnWidth:.7,
					layout:'form',
					items:[{
						xtype:'textfield',
						fieldLabel: '账号',
						name: '_user_code',
						id:'_user_code',
						anchor:'95%',
						allowBlank:false,
						blankText:'账户名不能为空',
						emptyText:'请输入账户名'
						}]
				},{
					columnWidth:.3,
					layout:'form',
					items:[
						new Ext.Button({
							text:'校验账号是否可用',
							handler:function(){
								if (!addSystemAdminRolePanel.findById('_user_code').validate()){
									Ext.Msg.show({
										title:'警告',
										msg: '请输入合法的账户名!',
										buttons: Ext.Msg.OK,
										icon: Ext.MessageBox.WARNING
									});
									addSystemAdminRolePanel.findById('_user_code').focus();
									return;
								}
								Ext.Ajax.request({
									url : 'CusAdmin!validateAccount.action',
									method:'post',
									params:{
										_user_code : addSystemAdminRolePanel.findById('_user_code').getValue()
									},
									success:function(result,response) {
										var responseTextVale = Ext.util.JSON.decode(result.responseText);
										if (responseTextVale.msg == 'true') {
											Ext.Msg.alert('提示','恭喜您!此账号未被注册');
										} else {
											Ext.Msg.alert('提示','抱歉!此账号已经被注册');
										}
									}
								});
							}
						})	
					]
				},{
					columnWidth:1,
					layout:'form',
					items:[{
						xtype:'textfield',
						fieldLabel: '显示用户名',
						name: '_user_name',
						id:'_user_name',
						anchor:'95%',
						allowBlank:false,
						emptyText:'请输入显示用户名',
						blankText:'显示用户名不能为空'
					},{
						xtype:'textfield',
						fieldLabel: '密码',
						inputType:"password",
						name: '_user_pwd',
						id:'_user_pwd',
						anchor:'95%',
						allowBlank:false,
						blankText : '密码不能为空'
					},{
						xtype:'textfield',
						fieldLabel: '确认密码',
						inputType:"password",
						name: '_user_pwd_confirm',
						id:'_user_pwd_confirm',
						anchor:'95%',
						allowBlank:false,
						blankText : '请再次输入密码'
					}]
				 }]
			}]
	});

	var win = new Ext.Window({
		buttonalign : 'right',
		closable: true,
		draggable : true,
		//height : 200,
		//layout : 'border',
		region : 'center',
		plain : true,
		items : [addSystemAdminRolePanel],
		title: '新增系统管理员账户',
		width : 450,
		buttons : [{
			text:'保存',
			id : '_btnSave',
			handler:function(){
				if (!addSystemAdminRolePanel.getForm().isValid()) {
					return;
				}
				if (addSystemAdminRolePanel.findById('_user_pwd').getValue() != addSystemAdminRolePanel.findById('_user_pwd_confirm').getValue()){
					Ext.Msg.show({
						titile:'警告',
						msg:'两次密码不相符,请再次确认密码',
						buttons: Ext.Msg.OK,
						icon:Ext.MessageBox.WARNING
					});
					addSystemAdminRolePanel.findById('_user_pwd_confirm').focus();
					return;
				}
				addSystemAdminRolePanel.getForm().submit({
					success: function(form, action){
						var responseTextVale = Ext.util.JSON.decode(action.response.responseText);
						//账户已经存在,添加失败
						if (responseTextVale.msg == 'AccountHasExistedException') {
							//Ext.Msg.alert('警告','账户名已存在,无法成功添加该账户!');	
							Ext.Msg.show({
								title:'警告',
								msg: '账户名已存在,无法成功添加该账户!',
							    buttons: Ext.Msg.OK,
							    icon: Ext.MessageBox.WARNING
							});
						}
						if (responseTextVale.msg == '' || responseTextVale.msg == null){
							if (grid != null) {
								grid.getStore().reload();
							}
							//accountGrid.getStore().reload();
							win.hide();
						}
					},
					failure: function(form, action) {
						Ext.Msg.alert('警告','由于异常原因,操作无法完成!');
					}
				});	
			}
		},{
			text:'取消',
			id:'_btnCancel',
			handler : function(){
				//alert(addSystemAdminRolePanel.getForm().url);
				win.hide();
			}
		}],
		listeners : {"beforedestroy" : function(obj) {
				return false;
			},"beforeshow":function(obj) {
				return true;
			},"beforehide":function(obj) {
				addSystemAdminRolePanel.getForm().reset();
				return true;
			}
		}
	});
	return win
}